package dormouse.vfs.metadata;

import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.apache.commons.vfs2.FileObject;

/**
 * This base class provides a minimal implementation of a reader.
 */
public abstract class AbstractMetaDataReader implements IMetadataReader {
    
	/** A map of the file metadata. */
    protected Map<String, String> metadata = new TreeMap<String, String>();
    
    /** A list of supported file extensions. */
    private String[] exts = null;
    

    @Override
    public String[] getFileExtensions() {
       return this.exts;
    }
    
    /**
     * Sets the file extensions supported by this reader.
     * @param exts
     */
    public void setFileExtensions(String[] exts){
    	this.exts = exts;
    }

    @Override
    public Set<String> getMetadataKeys() {
        return this.metadata.keySet();
    }
    
    @Override
    public String getMetadataValue(FileObject file, String key) throws IOException {
        if (this.metadata == null || this.metadata.isEmpty()){
        	this.getMetadata(file);
        }
        return this.metadata.get(key);
    }

    
    

}
